const koa = require('koa');
const Router = require('koa-router');
const cors = require('koa2-cors');
const bodyParser = require('koa-bodyparser');
const static = require('koa-static');

// 导入子路由
const index = require('./src/router/index');

// 创建koa实例
const app = new koa();

const router = new Router();
// 跨域设置
app.use(cors());
app.use(bodyParser());
// 设置静态资源文件夹的路径
app.use(static(__dirname + '/public'));


// 挂载子路由
router.use('/api', index.routes(), index.allowedMethods());

// 挂载路由中间件
app.use(router.routes()).use(router.allowedMethods());

// 监听端口
app.listen(80, () => {
    console.log('Server is running on port 80');
});
